




//
//  XJToolClass.m
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/9.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "XJToolClass.h"

@implementation XJToolClass

+ (BOOL)isUrl:(NSString *)UrlBool;
{
    if(self == nil)
        return NO;
    NSString *url;
    if (UrlBool.length>4 && [[UrlBool substringToIndex:4] isEqualToString:@"www."]) {
        UrlBool = [NSString stringWithFormat:@"http://%@",self];
    }else{
        UrlBool = UrlBool;
    }
    NSString *urlRegex = @"(https|http|ftp|rtsp|igmp|file|rtspt|rtspu)://((((25[0-5]|2[0-4]\\d|1?\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|1?\\d?\\d))|([0-9a-z_!~*'()-]*\\.?))([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\.([a-z]{2,6})(:[0-9]{1,4})?([a-zA-Z/?_=]*)\\.\\w{1,5}";
    NSPredicate* urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegex];
    return [urlTest evaluateWithObject:url];
}

//当前用户手机号
+ (void)SaveCurrentPhone:(NSString *)phonenumber{
    
     [[NSUserDefaults standardUserDefaults] setObject:phonenumber forKey:@"Current_phoneNumber"];
}

+ (NSString *)getCurrentPhoneStr{
    
    NSString *account = [[NSUserDefaults standardUserDefaults] objectForKey:@"Current_phoneNumber"];
    if (!account) {
        account = @"";
    }
    return account;
}

+ (void)removePhonenumber{
    
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Current_phoneNumber"];
}

+ (void)showAlertTitle:(NSString *)title Message:(NSString *)message
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

+ (void)savePasswd:(NSString *)password
{
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:@"user_passwd"];
}
+ (NSString *)getPassword
{
    NSString *passwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_passwd"];
    if (!passwd) {
        passwd = @"";
    }
    return passwd;
}
+ (void)removePasswd
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"user_passwd"];
}

+ (void)saveAccount:(NSString *)account
{
    [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"user_phone"];
}
+ (NSString *)getAccount
{
    NSString *account = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_phone"];
    if (!account) {
        account = @"";
    }
    return account;
}
+ (void)removeAccount
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"user_phone"];
}

#pragma mark -- 昵称
+ (void)saveNickname:(NSString *)Nickname{
    [[NSUserDefaults standardUserDefaults] setObject:Nickname forKey:@"nick_name"];
}

+ (NSString *)getNickname{
    NSString *account = [[NSUserDefaults standardUserDefaults] objectForKey:@"nick_name"];
    if (!account) {
        account = @"";
    }
    return account;
}
+ (void)removeNickname{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"nick_name"];
}

#pragma mark -- 头像
+ (NSString *)getAvater {
    NSString *avater = [[NSUserDefaults standardUserDefaults] objectForKey:@"avater"];
    if (!avater) {
        avater = @"";
    }
    return avater;
}

+ (void)saveAvater:(NSString *)avater {
    [[NSUserDefaults standardUserDefaults] setObject:avater forKey:@"avater"];
}

+ (void)removeAvater {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"avater"];
}

+ (void)removeTicketCheck{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ticketCheck"];
}
+ (void)saveticketCheck:(NSString *)ticketCheck{
    [[NSUserDefaults standardUserDefaults] setObject:ticketCheck forKey:@"ticketCheck"];
}
+ (NSString *)getTicketCheck{
    NSString *creatorId = [[NSUserDefaults standardUserDefaults] objectForKey:@"ticketCheck"];
    return creatorId;
}

//移除头像地址
+ (void)removeHeadImg{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"headimg"];
}

//保存头像地址
+ (void)saveHeadImg:(NSString *)imgUrl{
    [[NSUserDefaults standardUserDefaults] setObject:imgUrl forKey:@"headimg"];
}
+ (NSString *)getHeadImg{
    NSString *creatorId = [[NSUserDefaults standardUserDefaults] objectForKey:@"headimg"];
    return creatorId;
}
//保存用户设备识别码

+ (NSString *)getUUID{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"];
}
+ (void)saveUUID:(NSString *)uuidStr{
    [[NSUserDefaults standardUserDefaults] setObject:uuidStr forKey:@"UUID"];
}

//保存用户信息
+ (NSDictionary *)getUserDic{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"0-userdict"];
}

+ (void)saveUserDic:(NSDictionary *)userDic{
    [[NSUserDefaults standardUserDefaults] setObject:userDic forKey:@"0-userdict"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (void)removeUserdic{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"0-userdict"];
}

//16：52格式的时间换算成整数
+(NSInteger)timeChangeint:(NSString*)time{
    NSInteger index;
    NSArray *arr =[time componentsSeparatedByString:@":"];
    if (arr.count==2) {
        index=[arr[0] integerValue]*60+[arr[1] integerValue];
        return index;
    }else{
        return 0;
    }
}

#pragma mark--用户信息
+ (void)removeUserId
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"account_userid"];
}

+ (NSString *)getUserId
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"account_userid"];
}

+ (void)saveUserId:(NSString *)userId
{
    [[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"account_userid"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


+ (void)saveThirdLoginPlatform:(NSInteger)platform
{
    [[NSUserDefaults standardUserDefaults] setInteger:platform forKey:@"login_platform"];
}

//保存导航信息
+ (void)saveNavArr:(NSMutableArray *)navArr{
    [[NSUserDefaults standardUserDefaults] setObject:navArr forKey:@"navArr"];
}
+ (NSMutableArray *)getNavArr{
    NSMutableArray *passwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"navArr"];
    return passwd;
}
+ (void)removeNavArr{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"navArr"];
}



//保存地图搜索记录
+ (void)saveSearchArr:(NSMutableArray *)Arr{
    [[NSUserDefaults standardUserDefaults] setObject:Arr forKey:@"searchArr"];
}
+ (NSMutableArray *)getSearchArr{
    NSMutableArray *passwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"searchArr"];
    return passwd;
}
+ (void)removeSearchArr{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"searchArr"];
}

+ (void)saveBrightIndoorSearchArr:(NSMutableArray *)Arr{
    [[NSUserDefaults standardUserDefaults] setObject:Arr forKey:@"brightIndoorSearchArr"];
}
+ (NSMutableArray *)getBrightIndoorSearchArr{
    NSMutableArray *passwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"brightIndoorSearchArr"];
    return passwd;
}
+ (void)removeBrightIndoorSearchArr{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"brightIndoorSearchArr"];
}

//过滤掉字典中的null
+ (id)changeType:(id)myObj{
    if ([myObj isKindOfClass:[NSDictionary class]])
    {
        return [self nullDic:myObj];
    }
    else if([myObj isKindOfClass:[NSArray class]])
    {
        return [self nullArr:myObj];
    }
    else if([myObj isKindOfClass:[NSString class]])
    {
        return [self stringToString:myObj];
    }
    else if([myObj isKindOfClass:[NSNull class]])
    {
        return [self nullToString];
    }
    else
    {
        return myObj;
    }
}
//将NSDictionary中的Null类型的项目转化成@""
+(NSDictionary *)nullDic:(NSDictionary *)myDic
{
    NSArray *keyArr = [myDic allKeys];
    NSMutableDictionary *resDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < keyArr.count; i ++)
    {
        id obj = [myDic objectForKey:keyArr[i]];
        
        obj = [self changeType:obj];
        
        [resDic setObject:obj forKey:keyArr[i]];
    }
    return resDic;
}

//将NSDictionary中的Null类型的项目转化成@""
+(NSArray *)nullArr:(NSArray *)myArr
{
    NSMutableArray *resArr = [[NSMutableArray alloc] init];
    for (int i = 0; i < myArr.count; i ++)
    {
        id obj = myArr[i];
        
        obj = [self changeType:obj];
        
        [resArr addObject:obj];
    }
    return resArr;
}

//将NSString类型的原路返回
+(NSString *)stringToString:(NSString *)string
{
    return string;
}

//将Null类型的项目转化成@""
+(NSString *)nullToString
{
    return @"";
}
//保存token
+ (NSString *)getToken{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
}

+ (void)saveToken:(NSString *)tokenStr{
    [[NSUserDefaults standardUserDefaults] setObject:tokenStr forKey:@"token"];
    
}
+ (void)removeToken{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"];
}

+ (UIViewController*)viewController:(UIView *)view {
    UIResponder *nextResponder =  view;
    
    do
    {
        nextResponder = [nextResponder nextResponder];
        
        if ([nextResponder isKindOfClass:[UIViewController class]])
            return (UIViewController*)nextResponder;
        
    } while (nextResponder != nil);
    
    return nil;
}

+(AppDelegate *)appdelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}

//判断是否是有效的邮箱
+(BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

//搜索记录动画
+ (void)setAnimationOfSwingAroundWith:(UIView *)view
{
    [UIView animateWithDuration:0.56 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        view.center = CGPointMake(view.center.x - 10, view.center.y);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
            view.center =CGPointMake(view.center.x + 15, view.center.y);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
                view.center = CGPointMake(view.center.x - 5, view.center.y);
            } completion:^(BOOL finished) {
                
            }];
        }];
    }];
}
//注册界面错误信息的动画提示
+ (void)fastAnimationOfSwingAroundWith:(UIView *)view
{
    [UIView animateWithDuration:0.1 animations:^{
        view.transform = CGAffineTransformTranslate(view.transform,10, 0);
    } completion:^(BOOL finished) {
        view.transform = CGAffineTransformIdentity;
    }];
    
}
//判断是否有中文
+ (BOOL)IsChinese:(NSString *)str
{
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff)
        {
            return YES;
        }
    }
    return NO;
}
//获取随机验证码
+ (NSString *)getVerificationCode
{
    NSArray *strArr = [[NSArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",nil] ;
    NSMutableString *getStr = [[NSMutableString alloc]initWithCapacity:5];
    for(int i = 0; i < 6; i++) //得到六位随机字符,可自己设长度
    {
        int index = arc4random() % ([strArr count]);  //得到数组中随机数的下标
        [getStr appendString:[strArr objectAtIndex:index]];
        
    }
    
    return getStr;
}

+ (NSString *)md5:(NSString *)str
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, (unsigned int)strlen(cStr), result); // This is the md5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}

+ (NSString *)sha1:(NSString *)str{
    const char *cStr=[str cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data=[NSData dataWithBytes:cStr length:str.length];
    
    uint8_t disgest[CC_SHA1_DIGEST_LENGTH];
    
    CC_SHA1(data.bytes, data.length, disgest);
    
    NSMutableString *output=[NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH*2];
    
    for (int i=0; i<CC_SHA1_DIGEST_LENGTH; i++) {
        [output appendFormat:@"%02x",disgest[i]];
    }
    
    return output;
}

//判断合法的电话号码
+ (BOOL)checkTel:(NSString *)str
{
    
    if ([str length] == 0) {
        return NO;
    }
    //    NSString *regex =@"^((1[0-9][0-9])|(1[0-9][0-9])|(1[0-9][^4,\\D])|(1[0-9][0,5-9]))\\d{8}$";
     NSString *regex = @"^1(3[0-9]|4[579]|5[0-35-9]|7[0135-8]|8[0-9])\\d{8}$";
//    NSString *regex = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    if (!isMatch) {
        return NO;
    }
    return YES;
}

//判断输入是否为空格
+(BOOL)isEmpty:(NSString *) str {
    if (!str) {
        return YES;
    } else {
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];
        
        if ([trimedString length] == 0) {
            return YES;
        } else {
            return NO;
        }
    }
}

//交互式请求登录
+(BOOL) isLogin:(UIViewController *)viewController
{
    if ([XJToolClass getUserDic]!=nil) {
        return true;
    }
    else
    {
#warning 交互式登录
//        LoginVC *login = [[LoginVC alloc] init];
//        login.isPrsent = YES;
//        BaseNavgationController *nav = [[BaseNavgationController alloc]initWithRootViewController:login];
//        [viewController presentViewController:nav animated:YES completion:nil];
        return false;
    }
}

//提示成功提问 成功收藏 成功点赞
+ (void)tipAnimationWith:(NSString *)title
{
    UIWindow * win = [[[UIApplication sharedApplication] delegate] window];
    UILabel *likeLable;
    if (likeLable == nil) {
        UILabel *likeLable=[[UILabel alloc]init];
        
        likeLable.backgroundColor=[UIColor blackColor];
        likeLable.layer.cornerRadius = 5;
        likeLable.layer.masksToBounds = YES;
        likeLable.alpha=0.8;
        likeLable.textAlignment=NSTextAlignmentCenter;
        likeLable.font=[UIFont systemFontOfSize:12];
        likeLable.text=title;
        CGRect rect =[title boundingRectWithSize:CGSizeMake(1000, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
        likeLable.bounds = CGRectMake(0, 0, rect.size.width + 20, 30);
        //[likeLable sizeToFit];
        likeLable.center = CGPointMake(ScreenWidth/2, ScreenHeight - 100);
        
        likeLable.textColor=[UIColor whiteColor];
        
        [UIView animateWithDuration:2 animations:^{
            //            likeLable.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT-80);
            likeLable.alpha = 1;
        } completion:^(BOOL finished)
         {
             [UIView animateWithDuration:1 animations:^{
                 [likeLable removeFromSuperview];
             }];
         }];
        
        [win addSubview:likeLable];
    }
}

+ (void)bigShowMessage:(NSString *)message
{
    UIWindow * win = [[[UIApplication sharedApplication] delegate] window];
    UIView *coverView;
    if (coverView == nil) {
        UIView *coverView = [[UIView alloc]initWithFrame:win.bounds];
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.5;
        [win addSubview:coverView];
        
        UILabel *likeLable=[[UILabel alloc]init];
        likeLable.backgroundColor=[UIColor whiteColor];
        likeLable.layer.cornerRadius = 10;
        likeLable.layer.masksToBounds = YES;
        likeLable.alpha=0.8;
        likeLable.textAlignment=NSTextAlignmentCenter;
        likeLable.font=[UIFont systemFontOfSize:15];
        likeLable.text=message;
        likeLable.bounds = CGRectMake(0, 0, ScreenWidth-120, 150);
        likeLable.center = CGPointMake(ScreenWidth/2, 200);
        likeLable.textColor=[UIColor grayColor];
        [win addSubview:likeLable];
        
        [UIView animateWithDuration:2 animations:^{
            likeLable.alpha = 1;
        } completion:^(BOOL finished)
         {
             [UIView animateWithDuration:1 animations:^{
                 [likeLable removeFromSuperview];
                 [coverView removeFromSuperview];
             }];
         }];
    }
}

//判断是否为整形数字
+ (BOOL)isPureInt:(NSString *)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}

+(NSString *)urlencode:(NSString *) str
{
    NSMutableString *output = [NSMutableString string];
    const unsigned char *source = (const unsigned char *)[str UTF8String];
    unsigned long sourceLen = strlen((const char *)source);
    for (int i = 0; i < sourceLen; ++i) {
        const unsigned char thisChar = source[i];
        if (thisChar == ' '){
            [output appendString:@"+"];
        } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
                   (thisChar >= 'a' && thisChar <= 'z') ||
                   (thisChar >= 'A' && thisChar <= 'Z') ||
                   (thisChar >= '0' && thisChar <= '9')) {
            [output appendFormat:@"%c", thisChar];
        } else {
            [output appendFormat:@"%%%02X", thisChar];
        }
    }
    return output;
}
//解析 图片宽高
+ (NSDictionary *)pictureWidthAndHeight:(NSString *)str
{
    NSData * data = [str dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary * result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    return  result;
    
}
//压缩图片
+ (UIImage *)imageWithMaxSide:(CGFloat)length sourceImage:(UIImage *)image
{
    CGFloat scale = [[UIScreen mainScreen] scale];
    CGSize imgSize = CWSizeReduce(image.size, length);
    UIImage *img = nil;
    
    UIGraphicsBeginImageContextWithOptions(imgSize, YES, scale);  // 创建一个 bitmap context
    
    [image drawInRect:CGRectMake(0, 0, imgSize.width, imgSize.height)
            blendMode:kCGBlendModeNormal alpha:1.0];              // 将图片绘制到当前的 context 上
    
    img = UIGraphicsGetImageFromCurrentImageContext();            // 从当前 context 中获取刚绘制的图片
    UIGraphicsEndImageContext();
    
    return img;
}
static inline
CGSize CWSizeReduce(CGSize size, CGFloat limit)   // 按比例减少尺寸
{
    CGFloat max = MAX(size.width, size.height);
    if (max < limit) {
        return size;
    }
    
    CGSize imgSize;
    CGFloat ratio = size.height / size.width;
    
    if (size.width > size.height) {
        imgSize = CGSizeMake(limit, limit*ratio);
    } else {
        imgSize = CGSizeMake(limit/ratio, limit);
    }
    
    return imgSize;
}


+(NSString *)number:(float) price
{
    NSString *priceStr = [NSString stringWithFormat:@"%.1f",price];
    if (priceStr.length>=9) {
        return [NSString stringWithFormat:@"%@万",[priceStr substringToIndex:priceStr.length-6]];
    }
    return priceStr;
}
+(void)setbackNavagationItemwith:(UIViewController *)vc
{
    //去掉返回按钮的title
    UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title=@"";
    vc.navigationItem.backBarButtonItem = temporaryBarButtonItem;
}
+(int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
    
}

/**
 *  根据生日返回星座
 *
 *  @param birthday 出生日期
 *
 *  @return 星座
 */
+ (NSString*)getConstellationFromBirthday:(NSDate*)birthday{
    NSCalendar *myCal = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSDateComponents *comp1 = [myCal components:NSCalendarUnitMonth| NSCalendarUnitDay fromDate:birthday];
    
    NSInteger month = [comp1 month];
    
    
    NSInteger day = [comp1 day];
    
    return [self getAstroWithMonth:month day:day];
}

//得到星座的算法
+ (NSString *)getAstroWithMonth:(NSInteger)m day:(NSInteger)d{
    
    NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
    
    NSString *astroFormat = @"102123444543";
    
    NSString *result;
    
    if (m<1||m>12||d<1||d>31){
        
        return @"错误日期格式!";
        
    }
    
    if(m==2 && d>29)
        
    {
        
        return @"错误日期格式!!";
        
    }else if(m==4 || m==6 || m==9 || m==11) {
        
        if (d>30) {
            
            return @"错误日期格式!!!";
            
        }
        
    }
    
    result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(m*2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19))*2,2)]];
    
    return [result stringByAppendingString:@"座"];
}
// 根据颜色16进制数值得到UIColor
+ (UIColor *)colorFromHexRGB:(NSString *)inColorString{
    UIColor *result = nil;
    unsigned int colorCode = 0;
    unsigned char redByte, greenByte, blueByte;
    
    if (nil != inColorString)
    {
        NSScanner *scanner = [NSScanner scannerWithString:inColorString];
        (void) [scanner scanHexInt:&colorCode]; // ignore error
    }
    redByte = (unsigned char) (colorCode >> 16);
    greenByte = (unsigned char) (colorCode >> 8);
    blueByte = (unsigned char) (colorCode); // masks off high bits
    result = [UIColor
              colorWithRed: (float)redByte / 0xff
              green: (float)greenByte/ 0xff
              blue: (float)blueByte / 0xff
              alpha:1.0];
    return result;
}

//天气图片
+ (NSString *)weatherImg:(NSString *)weather{
    if ([weather isEqualToString:@"阴"]) {
        return @"icon_homepage_1";
    }else if([weather isEqualToString:@"多云"]){
        return @"icon_homepage_2";
    }else if([weather isEqualToString:@"小雨"]||[weather isEqualToString:@"雨"]){
        return @"icon_homepage_3";
    }else if([weather isEqualToString:@"雾"]||[weather isEqualToString:@"浓雾"]||[weather isEqualToString:@"强浓雾"]||[weather isEqualToString:@"大雾"]||[weather isEqualToString:@"特强浓雾"]){
        return @"icon_homepage_4";
    }else if([weather isEqualToString:@"霾"]||[weather isEqualToString:@"中度霾"]||[weather isEqualToString:@"重度霾"]||[weather isEqualToString:@"严重霾"]){
        return @"icon_homepage_5";
    }else if([weather isEqualToString:@"浮尘"]){
        return @"icon_homepage_6";
    }else if([weather isEqualToString:@"冻雨"]){
        return @"icon_homepage_7";
    }else if([weather isEqualToString:@"雷阵雨"]){
        return @"icon_homepage_8";
    }else if([weather isEqualToString:@"雷阵雨伴有冰雹"]){
        return @"icon_homepage_9";
    }else if([weather isEqualToString:@"阵雨"]){
        return @"icon_homepage_10";
    }else if([weather isEqualToString:@"中雨"]){
        return @"icon_homepage_11";
    }else if([weather isEqualToString:@"大雨"]||[weather isEqualToString:@"暴雨"]||[weather isEqualToString:@"特大暴雨"]||[weather isEqualToString:@"大暴雨"]){
        return @"icon_homepage_12";
    }else if([weather isEqualToString:@"强沙尘暴"]||[weather isEqualToString:@"沙尘暴"]){
        return @"icon_homepage_13";
    }else if([weather isEqualToString:@"大雪"]||[weather isEqualToString:@"暴雪"]||[weather isEqualToString:@"大雪-暴雪"]){
        return @"icon_homepage_14";
    }else if([weather isEqualToString:@"中雪"]||[weather isEqualToString:@"阵雪"]){
        return @"icon_homepage_15";
    }else if([weather isEqualToString:@"小雪"]||[weather isEqualToString:@"雪"]){
        return @"icon_homepage_16";
    }else if([weather isEqualToString:@"晴"]){
        return @"icon_homepage_17";
    }else if([weather isEqualToString:@"扬沙"]){
        return @"icon_homepage_18";
    }else if([weather isEqualToString:@"雨夹雪"]){
        return @"icon_homepage_19";
    }else{
        return nil;
    }
}
+ (BOOL)checkCardNo:(NSString*) cardNo{
    int oddsum = 0;     //奇数求和
    int evensum = 0;    //偶数求和
    int allsum = 0;
    int cardNoLength = (int)[cardNo length];
    int lastNum = [[cardNo substringFromIndex:cardNoLength-1] intValue];
    
    cardNo = [cardNo substringToIndex:cardNoLength - 1];
    for (int i = cardNoLength -1 ; i>=1;i--) {
        NSString *tmpString = [cardNo substringWithRange:NSMakeRange(i-1, 1)];
        int tmpVal = [tmpString intValue];
        if (cardNoLength % 2 ==1 ) {
            if((i % 2) == 0){
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{
                oddsum += tmpVal;
            }
        }else{
            if((i % 2) == 1){
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{
                oddsum += tmpVal;
            }
        }
    }
    
    allsum = oddsum + evensum;
    allsum += lastNum;
    if((allsum % 10) == 0)
        return YES;
    else
        return NO;
}
+ (NSString *)showVisibleCard:(NSString *)cardNumber
{
    if (![XJToolClass checkCardNo:cardNumber]) {
        return cardNumber;
    };
    NSString *inVisibleTel = [cardNumber stringByReplacingCharactersInRange:NSMakeRange(0, cardNumber.length-4) withString:@"**** **** ****"];
    return inVisibleTel;
}
//字符串空格转换成数组
+(NSArray *)spaceStrChangeArr:(NSString *)str{
    NSArray *b = [str componentsSeparatedByString:@" "];
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSString *string in b) {
        if (string.length!=0) {
            [array addObject:string];
        }
    }
    return array;
}
//字符串逗号转换成数组
+(NSArray *)commaStrChangeArr:(NSString *)str{
    NSArray *b = [str componentsSeparatedByString:@","];
    return b;
}
//日期月份英文简称
+(NSString *)mon:(NSString *)data{
    //    NSArray *arr = [data componentsSeparatedByString:@" "];
    NSString *mon = data;
    if ([mon isEqualToString:@"01"]) {
        mon=@"January";
    }else if ([mon isEqualToString:@"02"]){
        mon=@"February";
    }else if ([mon isEqualToString:@"03"]){
        mon=@"March";
    }else if ([mon isEqualToString:@"04"]){
        mon=@"April";
    }else if ([mon isEqualToString:@"05"]){
        mon=@"May";
    }else if ([mon isEqualToString:@"06"]){
        mon=@"June";
    }else if ([mon isEqualToString:@"07"]){
        mon=@"July";
    }else if ([mon isEqualToString:@"08"]){
        mon=@"August";
    }else if ([mon isEqualToString:@"09"]){
        mon=@"September";
    }else if ([mon isEqualToString:@"10"]){
        mon=@"October";
    }else if ([mon isEqualToString:@"11"]){
        mon=@"November";
    }else if ([mon isEqualToString:@"12"]){
        mon=@"December";
    }
    //    return [NSString stringWithFormat:@"%@ %@ %@",arr[0],mon,arr[2]];
    return mon;
}
//时间戳转字符串"--"
+ (NSString*)stringFromTimeInterval:(NSTimeInterval)time{
    
    //设定时间格式,这里可以设置成自己需要的格式
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // [dateFormatter setDateFormat:@"MM月dd"];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    //这里比较关键,需要将NSTimeInterval除以1000
    NSString *iosDate = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:time]];
    return iosDate;
}

//时间戳转字符串"-- MM-dd HH:mm"
+(NSString*)stringFromTimeIntervalThree:(NSTimeInterval)time{
    //设定时间格式,这里可以设置成自己需要的格式
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // [dateFormatter setDateFormat:@"MM月dd"];
    [dateFormatter setDateFormat:@"MM-dd HH:mm"];
    
    //这里比较关键,需要将NSTimeInterval除以1000
    NSString *iosDate = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:time]];
    return iosDate;
}

//时间戳转字符串"//"
+(NSString*)stringFromTimeIntervalTwo:(NSTimeInterval)time{
    //设定时间格式,这里可以设置成自己需要的格式
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // [dateFormatter setDateFormat:@"MM月dd"];
    [dateFormatter setDateFormat:@"HH:mm"];
    
    //这里比较关键,需要将NSTimeInterval除以1000
    NSString *iosDate = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:time]];
    return iosDate;
}

+ (NSString *)getTimeByTimeinterval:(double)interval DateFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:interval];
    NSString *time = [dateFormatter stringFromDate:date];
    return time;
}
+ (double)getTime:(NSString *)interval DateFormat:(NSString *)dateFormat{
    //    NSDate * senddate=[NSDate dateWithString:interval format:dateFormat];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:dateFormat];
    //    NSString *  locationString=[dateformatter stringFromDate:dateformatter];
    //    NSDate * now = [dateformatter dateFromString:locationString];
    NSDate* date = [dateformatter dateFromString:interval];
    //    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[senddate timeIntervalSince1970]];
    return [date timeIntervalSince1970];
}

//发帖回复时间
+ (NSString *)getTimeDescription:(NSTimeInterval)timeInerval
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInerval];
    int timer = fabs([date timeIntervalSinceNow]);
    NSString *time = @"";
    time = [NSString stringWithFormat:@"%d天前",(int)timer/(3600*24)];
    return time;
}


+ (UIImage *)scaleToSize:(UIImage *)originImage Width:(CGFloat)scaleWidth
{
    float width = originImage.size.width;
    float height = originImage.size.height;
    
    if (width>scaleWidth) {
        height = scaleWidth*height/width;
        width = scaleWidth;
        
        UIGraphicsBeginImageContext(CGSizeMake(width, height));
        [originImage drawInRect:CGRectMake(0,0, width, height)];
        // 从当前context中创建一个改变大小后的图片
        UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
        // 使当前的context出堆栈
        UIGraphicsEndImageContext();
        //返回新的改变大小后的图片
        return scaledImage;
    }
    else{
        return originImage;
    }
    
}
+(UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height
{
    CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
    UIGraphicsBeginImageContext(r.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, r);
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}
+ (NSString *)setfloor:(long )floor{
    if (floor==1921484) {
        return @"F1";
    }else if (floor==1922168){
        return @"F3";
    }else if(floor==1932821){
        return @"F4";
    }else{
        return nil;
    }
}

+ (NSMutableArray *)AddDefaultMutArr{
    
    NSMutableArray *passwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"addmutarr"];
    return passwd;
}

//获取时间字符串
+ (NSString *)getCurrentTimeString:(NSString *)dataFormate Date:(NSDate *)date
{
    NSDateFormatter *formater = [[NSDateFormatter alloc]init];
    formater.dateFormat = dataFormate;
    NSString *time = [formater stringFromDate:date];
    return time;
}
//加阴影
+ (void)putShadowOnView:(UIView *)view Radius:(CGFloat)radius Color:(CGColorRef)color ShadowRadius:(CGFloat)sRadius Opacity:(float)opacity
{
    view.layer.cornerRadius = radius;
    view.layer.shadowColor = color;//shadowColor阴影颜色
    view.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    view.layer.shadowOpacity = opacity;//阴影透明度，默认0
    view.layer.shadowRadius = sRadius;//阴影半径，默认3
}

+ (void)showLocationOpenTip:(UIViewController *)viewControler
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"定位服务未开启" message:@"关闭定位会导致部分功能无法正常使用，您可以在系统设置-隐私-定位服务找到喜脚么app，打开定位服务" preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:^(BOOL success) {
            
        }];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [viewControler presentViewController:alertController animated:YES completion:nil];
}
+(NSString *)iphoneType{
    
    
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
    
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
    
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";
    
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";
    
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";
    
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";
    
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    
    if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
    
    if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
    
    if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
    
    if ([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
    
    if ([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
    
    if ([platform isEqualToString:@"iPhone10,3"]) return @"iPhone X";
    
    if ([platform isEqualToString:@"iPod1,1"])  return @"iPod Touch 1G";
    
    if ([platform isEqualToString:@"iPod2,1"])  return @"iPod Touch 2G";
    
    if ([platform isEqualToString:@"iPod3,1"])  return @"iPod Touch 3G";
    
    if ([platform isEqualToString:@"iPod4,1"])  return @"iPod Touch 4G";
    
    if ([platform isEqualToString:@"iPod5,1"])  return @"iPod Touch 5G";
    
    if ([platform isEqualToString:@"iPad1,1"])  return @"iPad 1G";
    
    if ([platform isEqualToString:@"iPad2,1"])  return @"iPad 2";
    
    if ([platform isEqualToString:@"iPad2,2"])  return @"iPad 2";
    
    if ([platform isEqualToString:@"iPad2,3"])  return @"iPad 2";
    
    if ([platform isEqualToString:@"iPad2,4"])  return @"iPad 2";
    
    if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini 1G";
    
    if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini 1G";
    
    if ([platform isEqualToString:@"iPad2,7"])  return @"iPad Mini 1G";
    
    if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3";
    
    if ([platform isEqualToString:@"iPad3,2"])  return @"iPad 3";
    
    if ([platform isEqualToString:@"iPad3,3"])  return @"iPad 3";
    
    if ([platform isEqualToString:@"iPad3,4"])  return @"iPad 4";
    
    if ([platform isEqualToString:@"iPad3,5"])  return @"iPad 4";
    
    if ([platform isEqualToString:@"iPad3,6"])  return @"iPad 4";
    
    if ([platform isEqualToString:@"iPad4,1"])  return @"iPad Air";
    
    if ([platform isEqualToString:@"iPad4,2"])  return @"iPad Air";
    
    if ([platform isEqualToString:@"iPad4,3"])  return @"iPad Air";
    
    if ([platform isEqualToString:@"iPad4,4"])  return @"iPad Mini 2G";
    
    if ([platform isEqualToString:@"iPad4,5"])  return @"iPad Mini 2G";
    
    if ([platform isEqualToString:@"iPad4,6"])  return @"iPad Mini 2G";
    
    if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
    
    if ([platform isEqualToString:@"x86_64"]) return @"iPhone Simulator";
    
    return platform;
    
}


@end
